package com.zis.system.web;

import com.zis.starter.core.ResponseEntity;
import com.zis.starter.core.SearchParams;
import com.zis.system.client.SysClient;
import com.zis.system.inter.ISysInter;
import com.zis.system.model.Sys;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * Create by wangshen 2018/1/23
 */
@RestController
@RequestMapping("/api/system/sys")
public class SysController {

    @Autowired
    private SysClient sysClient;

    /**
     * 分页查询
     * @param params
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public PageQuery<Sys> findByPage(@RequestBody SearchParams params) throws Exception {
        return sysClient.findByPage(params);
    }

    /**
     * 条件查询
     * @param params
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/condition", method = RequestMethod.POST)
    public ResponseEntity findByCondition(@RequestBody Map params) throws Exception {
        return sysClient.findByCondition(params);
    }

    /**
     * 新增
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public ResponseEntity insert(@RequestBody Sys model) throws Exception {
        return sysClient.insert(model);
    }

    /**
     * 修改
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ResponseEntity update(@RequestBody Sys model) throws Exception {
        return sysClient.update(model);
    }

    /**
     * 删除
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    public ResponseEntity delete(@PathVariable("id") String id) throws Exception {
        return sysClient.delete(id);
    }

    /**
     * 主键查询
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/select/{id}", method = RequestMethod.GET)
    public ResponseEntity selectById(@PathVariable("id") String id) throws Exception {
        return sysClient.selectById(id);
    }

    /**
     * 查询全部
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/all", method = RequestMethod.GET)
    public ResponseEntity findAllToJson() throws Exception {
        return sysClient.findAllToJson();
    }
}
